home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tptc17sc.zip / ATOI.INC next >
Text File  |  1988-03-25  |  928b  |  48 lines

  1.  
  2. (*
  3.  * converts ascii string to an integer value
  4.  * (tp3 dies on leading spaces but likes trailing.
  5.  *  tp4 likes leading spaces but dies on trailing!!)
  6.  *
  7.  *)
  8.  
  9. function atol (asc:  anystring): longint;
  10. var
  11.    i:             integer;
  12.    value:         longint;
  13.    num:           anystring;
  14.  
  15. begin
  16.    num := '';
  17.    for i := 1 to length(asc) do
  18.       if ((asc[i] >= '0') and (asc[i] <= 'F')) or (asc[i] = '$') then
  19.          num := num + asc[i];
  20.   
  21.    if length(num) = 0 then
  22.       value := 0
  23.    else
  24.       val(num, value, i);
  25.  
  26.    atol := value;
  27. end;
  28.  
  29.  
  30. function atoi (asc:  anystring): integer;
  31. begin
  32.    atoi := integer(atol(asc));
  33. end;
  34.  
  35. function atow (asc:  anystring): word;
  36. begin
  37.    atow := word(atol(asc) and $FFFF);
  38. end;
  39.  
  40. function htoi (asc:  anystring): word;
  41. begin
  42.    if copy(asc,1,2) = '0x' then
  43.       asc := '$' + copy(asc,3,99);
  44.    htoi := word(atol(asc) and $FFFF);
  45. end;
  46.  
  47.  
  48.